<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="root">root</div>
</body>
<script>
  const AutoUpdater = require( "nw-autoupdater" ),
    updater = new AutoUpdater( require( "./package.json" ), {
      strategy: "ScriptSwap"
    }),
    output =  document.querySelector( "#root" );

  async function main(){
    try {

      // Download/unpack update if any available
      const rManifest = await updater.readRemoteManifest();
      const needsUpdate = await updater.checkNewVersion( rManifest );
      if ( !needsUpdate ) {
        output.innerHTML += `\nApp is up to date...`;
        return;
      }
      if ( !confirm( "New release is available. Do you want to upgrade?" ) ) {
        return;
      }

      // Subscribe for progress events
      updater.on( "download", ( downloadSize, totalSize ) => {
        output.innerHTML = `Downloading...`;
        console.log( "download progress", Math.floor( downloadSize / totalSize * 100 ), "%" );
      });
      updater.on( "install", ( installFiles, totalFiles ) => {
        output.innerHTML = `Installing...\n`;
        console.log( "install progress", Math.floor( installFiles / totalFiles * 100 ), "%" );
      });

      const updateFile = await updater.download( rManifest );
      await updater.unpack( updateFile );
      alert( `The application will automatically restart to finish installing the update` );
      await updater.restartToSwap();
    } catch ( e ) {
      console.error( e );
    }
  }

  output.innerHTML = `Application ver. ${nw.App.manifest.version}\n`;

  main();
</script>
</html>